<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialog" fullscreen>
    <div>
      <el-button
        class="filter-item"
        size="mini"
        type="success"
        icon="el-icon-printer"
        @click="doPrint"
      >打印</el-button>
    </div>
    <printFrame ref="printFrame" :src="printHtmlUrl" iframe-id="barcodeprintFrame"/>
  </el-dialog>
</template>

<script>
import printFrame from '@/components/iframe/index'
import AdminUtilMng from '@/api/system/AdminUtilMng'

export default {
  components: { printFrame },
  props: {
    sup_this: {
      type: Object,
      default: null,
      required: true
    },
    barcodePrintType: {
      type: String,
      default: '',
      required: true
    }
  },
  data() {
    return {
      loading: false,
      dialog: false,
      printHtmlUrl: ''
    }
  },
  created() {
  },
  methods: {
    loadPrintPage(barcodeList) {
      this.dialog = true
      const data = { barcodePrintType: this.barcodePrintType, barcodeList: barcodeList }
      AdminUtilMng.doPrintBarcode(data).then(res => {
        localStorage.removeItem('barcodePrintHtml')
        localStorage.setItem('barcodePrintHtml', res.data)
        this.printHtmlUrl = process.env.BASE_ACCESS_URL + '/static/print/barcodePrint.html?random=' + Math.random()
        // this.printHtmlUrl = process.env.BASE_ACCESS_URL + res.data
      })
    },
    doPrint() {
      const iframe = document.getElementById('barcodeprintFrame')
      iframe.contentWindow.focus()
      iframe.contentWindow.print()
    },
    cancel() {
      this.resetForm()
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
    }
  }
}
</script>
